﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 职工端
{
    public partial class 个人信息修改 : Form
    {
        string constr = denglu.strcon;
        public static string account;
        public 个人信息修改()
        {
            InitializeComponent();
            sx();
        }
        void sx()
        {
            SqlConnection sqlcon = new SqlConnection(constr);
            sqlcon.Open();
            string sql = "select* from Worker where Waccount='" + account + "'";
            SqlCommand sqlcmd = new SqlCommand(sql, sqlcon);
            SqlDataReader Sdr = sqlcmd.ExecuteReader();
            while (Sdr.Read())
            {
                tbx_name.Text = Sdr["Wname"].ToString();//姓名
                tbx_phone.Text = Sdr["Wnumber"].ToString();//电话
                tbx_pwd.Text = Sdr["Wpassword"].ToString();//密码
            }
            sqlcon.Close();
        }
        private void btn_update_Click(object sender, EventArgs e)
        {
            SqlConnection sqlcon = new SqlConnection(constr);
            try
            {
                sqlcon.Open();
                string sql = "update Worker set Wname='"+tbx_name.Text+"',Wnumber='"+tbx_phone.Text+"',Wpassword='"+tbx_pwd.Text+"' where Waccount='"+account+"'";
                SqlCommand cmd = new SqlCommand(sql,sqlcon);
                int i=cmd.ExecuteNonQuery();
                if (i==1)
                {
                    MessageBox.Show("修改成功！");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString()+"修改失败");
            }finally
            {
                sqlcon.Close();
                sx();
            }
        }
    }
}
